<template>
  <div class="head">
    <div class="title">查询条件</div>
    <div class="line" />
    <el-row>
      <el-col :span="24">
        <div class="title1">
          <el-form ref="form" style="display: flex;flex-wrap: wrap;margin-top: 24px;justify-content: space-between;" :model="form" label-width="80px">
            <el-form-item style="margin-left: 0;" class="text" label="网点">
              <el-input v-model="form.name" :disabled="true" placeholder="辽宁盘锦公司" class="input" />
            </el-form-item>
            <el-form-item class="text" label="账单时间">
              <el-date-picker v-model="value" class="input1" type="daterange" value-format="yyyy-MM-dd" start-placeholder="开始月份" end-placeholder="结束月份" @change="changeTime" />
            </el-form-item>
            <el-form-item class="text" label="总部类别">
              <el-select v-model="form.hqType" class="input" placeholder="请选择">
                <el-option label="全部" value="1" />
                <el-option label="总部应收" value="2" />
                <el-option label="总部应付" value="3" />
              </el-select>
            </el-form-item>
            <div>
              <el-form-item>
                <el-button type="primary" @click="onSubmit">查询</el-button>
                <el-button @click="khClear">重置</el-button>
              </el-form-item>
            </div>
          </el-form>
        </div>
        <div class="title1">
          <el-form ref="form" style="display: flex;justify-content: space-between;flex-wrap: wrap;" :model="form" label-width="80px">
            <div>
              <el-form-item class="text" style="margin-left: 0;" label="账单状态">
                <el-select v-model="form.billType" class="input" placeholder="请选择">
                  <el-option label="全部" value="1" />
                  <el-option label="待确认账单" value="2" />
                  <el-option label="已确认账单" value="3" />
                  <el-option label="超时自动确认" value="4" />
                </el-select>
              </el-form-item>
            </div>
            <div>
              <el-form-item>
                <el-button @click="onSubmit"><i class="el-icon-upload2" />导出</el-button>
              </el-form-item>
            </div>
          </el-form>
        </div>
        <elltable v-loading="loading" :data="tableData" :th="th" />
        <div style="display: flex;justify-content: space-between;margin-top: 51px;">
          <div class="title2" />
          <div class="title2" />
          <div class="block" style="display: flex; justify-content: flex-end">
            <pagination background :current-page="form.pageDate.pageNum" :page-size="form.pageDate.pageSize" :total="total" @size-change="handleSizeChange" @current-change="handleCurrentChange" />
          </div>
        </div>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import { BillVerifyApi } from '@/api/HqFinancePanel'
export default {
  components: {},
  data() {
    return {
      loading: false,
      value: [],
      form: {
        billType: '',
        endTime: '',
        hqType: '',
        networkNameId: '辽宁盘锦公司',
        pageDate: {
          pageNum: 1,
          pageSize: 10
        },
        startTime: ''
      },
      tableData: [],
      current: 0, // 页数
      pages: 0, // 条数
      total: 0, // 总数
      th: []
    }
  },

  computed: {},

  created() { },

  methods: {
    // 序号
    table_index(index) {
      return (this.pages - 1) * this.current + index + 1
    },
    // 选择时间
    changeTime() {
      if (this.value != null) {
        this.form.startTime = this.value[0]
        this.form.endTime = this.value[1]
      }
    },
    // 上一页
    handleSizeChange(val) {
      this.form.pageDate.pageSize = val
      this.onSubmit()
    },
    // 下一页
    handleCurrentChange(val) {
      this.form.pageDate.pageNum = val
      this.onSubmit()
    },
    // 重置
    khClear() {
      Object.keys(this.form).forEach((key) => {
        if (key !== 'pageDate' && key !== 'networkNameId') {
          this.form[key] = ''
        }
      })
      this.tableData = []
      this.th = []
      this.value = []
      this.total = 0
    },
    // 查询
    async onSubmit() {
      // const params = {}
      // Object.keys(this.form).forEach(key => {
      //   if (this.form[key]) {
      //     params[key] = this.form[key]
      //   }
      // })
      this.loading = true
      const res = await BillVerifyApi(this.form)
      this.loading = false

      console.log('查询', res)
      if (res.code == 200) {
        this.tableData = res.data.list.data
        this.total = res.data.list.total
        this.th = res.data.fields
      } else {
        this.tableData = []
        this.total = 0
        this.th = []
      }
    }
  }
}

</script>
<style
  scoped
  lang="scss"
>
.head {
  padding: 30px;
}

.title {
  font-size: 16px;
  font-family: Source Han Sans CN;
  font-weight: 400;
  color: #666666;
}

.line {
  height: 1px;
  background: #d8d8d8;
  border-radius: 1px;
  margin-top: 19px;
}

.title1 {
  // display: flex;
  // justify-content: space-between;
  .text {
    font-size: 18px;
    font-family: Source Han Sans CN;
    font-weight: 400;
    color: #666666;

    // margin-left: 52px;
    .input {
      width: 286px;
      height: 36px;
      background: #ffffff;
      border-radius: 4px;
    }

    .input1 {
      width: 708px;
      height: 36px;
      background: #ffffff;
      border-radius: 4px;
    }
  }
}

.title2 {
  font-size: 18px;
  font-family: Source Han Sans CN;
  font-weight: 400;
  color: #666666;
}
</style>
